Page({
    data: {
        nickName: '',
        gender: '',
        avatarUrl: ''
    },
    noLogin() {
        wx.navigateTo({
            url: '/pages/index/index',
        })
    },
    getUserProfile: function (e) {
        wx.getUserProfile({
            desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
            success: res => {
                //拿到信息处理业务
                this.setData({
                    nickName: res.userInfo.nickName,
                    gender: res.userInfo.gender,
                    avatarUrl: res.userInfo.avatarUrl
                })
                this.login();
            }
        })
    },
    login: function () {
        wx.login({
            success: (res) => {
                wx.request({
                    url: 'http://127.0.0.1:3000/api/login',
                    data: {
                        code: res.code,
                        nickName: this.data.nickName,
                        gender:this.data.gender,
                        avatarUrl:this.data.avatarUrl
                    },
                    method: 'POST',
                    success: (res) => {
                        console.log(res)
                    }
                })
            }
        })
    },
    onLoad: function (options) {},
    onReady: function () {
        // 页面渲染完成
    },
    onShow: function () {
        // 页面显示
    },
    onHide: function () {
        // 页面隐藏
    },
    onUnload: function () {
        // 页面关闭
    }
})